<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <p>
            姓名：<input type="text" v-model='name'>
        </p>
        <p>
            城市：
            <select v-model='cityName'>
                <option value="">请选择</option>
                <option v-for="(item,index) in city" :value="item.k" :key="item.k">{{item.title}}</option>
            </select>
        </p>
    </div>
    <script src="../vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data () {
                return {
                    name:'',
                    city:[
                        {title:'南昌',k:'nc'},
                        {title:'高安',k:'ga'},
                        {title:'吉安',k:'ja'},
                        {title:'南阳',k:'ny'},
                        {title:'宜春',k:'yc'},
                    ],
                    cityName:'',
                }
            },
            watch: {
                name(newVal){
                    if(newVal=='熊'){
                        this.cityName='nc';
                    }
                    else if(newVal=='王'){
                        this.cityName='ga';
                    }
                    else if(newVal=='张'){
                        this.cityName='ja';
                    }
                    else if(newVal=='姬'){
                        this.cityName='ny';
                    }
                    else if(newVal==''){
                        this.cityName='yc';
                    }
                }
            }
        })
    </script>
</body>
</html>